﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace EsApp02
{

    public class EsAppService: IDynamicApiController
    {
        private IRepository<ActivityEntity> _repository;
        public EsAppService(IRepository<ActivityEntity> repository)
        {
            _repository = repository;
        }
        public string Get()
        {
            return $"现在时间：{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss}";
        }

        /// <summary>
        /// 读取活动数据
        /// </summary>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<ActivityEntity>> GetActivities([FromQuery] int limit)
        {
            var list = await _repository.AsQueryable(false).Take(limit).ToListAsync();
            return list;
        }

    }
}
